/* $Id: DatabaseTreeMouseListener.java 60 2010-02-01 19:54:35Z aaron.day $ */
package org.crazydays.gameplan.db.swing;


import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTree;
import javax.swing.tree.TreePath;

import org.crazydays.gameplan.controller.Controller;

/**
 * DatabaseTreeMouseListener
 */
public class DatabaseTreeMouseListener
    implements MouseListener
{
    /** controller */
    protected Controller controller;

    /**
     * Set controller.
     * 
     * @param controller Controller
     */
    public void setController(Controller controller)
    {
        this.controller = controller;
    }

    /**
     * @param event Event
     * @see MouseListener#mouseClicked(MouseEvent)
     */
    @Override
    public void mouseClicked(MouseEvent event)
    {
        JTree tree = (JTree) event.getComponent();
        int row = tree.getRowForLocation(event.getX(), event.getY());
        if (row < 0) {
            return;
        }

        TreePath path = tree.getPathForLocation(event.getX(), event.getY());

        tree.setSelectionPath(path);
        if (path.getLastPathComponent() instanceof MapNode) {
            controller.openGameMap(path.getLastPathComponent().toString());
        }
    }

    /**
     * @param event Event
     * @see MouseListener#mousePressed(MouseEvent)
     */
    @Override
    public void mousePressed(MouseEvent event)
    {
    }

    /**
     * @param event Event
     * @see MouseListener#mouseReleased(MouseEvent)
     */
    @Override
    public void mouseReleased(MouseEvent event)
    {
    }

    /**
     * @param event Event
     * @see MouseListener#mouseEntered(MouseEvent)
     */
    @Override
    public void mouseEntered(MouseEvent event)
    {
    }

    /**
     * @param event Event
     * @see MouseListener#mouseExited(MouseEvent)
     */
    @Override
    public void mouseExited(MouseEvent event)
    {
    }
}
